var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
    for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
        to[j] = from[i];
    return to;
};
export function formatUTCDate(date, format) {
    var e_1, _a;
    var o = new Map([
        ['M+', (date.getUTCMonth() + 1).toString()],
        ['d+', date.getUTCDate().toString()],
        ['h+', date.getUTCHours().toString()],
        ['m+', date.getUTCMinutes().toString()],
        ['s+', date.getUTCSeconds().toString()],
        ['q+', Math.floor((date.getUTCMonth() + 3) / 3).toString()],
        ['S', date.getUTCMilliseconds().toString()],
    ]);
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (date.getUTCFullYear() + '').substr(4 - RegExp.$1.length));
    }
    try {
        for (var _b = __values(o.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
            var k = _c.value;
            if (new RegExp('(' + k + ')').test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length === 1
                    ? o.get(k)
                    : ('00' + o.get(k)).substr(('' + o.get(k)).length));
            }
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
        }
        finally { if (e_1) throw e_1.error; }
    }
    return format;
}
export function getQueryObject(params) {
    var ret = new Map();
    if (params.indexOf('?') !== -1) {
        params = params.substr(1);
    }
    var strs = params.split('&');
    for (var i = 0; i < strs.length; i++) {
        ret.set(strs[i].split('=')[0], decodeURIComponent(strs[i].split('=')[1]));
    }
    return ret;
}
export function getSortedParams(map) {
    return __spreadArray([], __read(map)).sort()
        .map(function (i) { return i[0] + "=" + encodeURIComponent(i[1]); })
        .join('&');
}
